import { Controller, Get, Post, Body, Query, HttpCode, Req, } from '@nestjs/common';
import { UserService } from './user.service';
import { UserLoginDto } from './dto/user-login.dto';
import { UserInfoDto } from './dto/user-info.dto';
import { UserSearchDto } from './dto/user-search.dto';
import { UserRegisterDto } from './dto/user-register.dto';
import { CatsService } from 'src/cats/cats.service';
import { Request } from 'express';

@Controller({ path: 'user', host: 'localhost' })
export class UserController {
  constructor(
    private readonly userService: UserService,
    private catsService: CatsService
  ) { }

  @Post('login')
  userLogin(@Body() userLoginDto: UserLoginDto): UserInfoDto {
    return this.userService.userLogin(userLoginDto);
  }

  @Post('register')
  @HttpCode(200)
  async userRegister(@Body() userLoginDto: UserRegisterDto): Promise<boolean> {
    try {
      const result = await this.userService.userRegister(userLoginDto)
      return result.generatedMaps[0].uid
    } catch (error) {
      return error
    }
  }

  @Get('info')
  userInfoById(): Promise<UserInfoDto> {
    return this.userService.userInfo();
  }

  @Get('search')
  userSearch(@Query() userSearchDto: UserSearchDto) {
    return this.userService.userSearch(userSearchDto.keyword);
  }

  @Get('list')
  userList() {
    console.log('this.this.catsService.findAll(); :>> ', this.catsService.findAll());
    return this.userService.findAll()
  }
}
